/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode == 13){ 
		$("#hcpc-search").trigger('click');
		return false;
		}
	})
});
$("input:text").attr('autocomplete','off');
var dwpanduan;
var pageNumber;
// JSP参数获取
function getHaocaifpjlCanshu(preid,prepageNo,preMingcheng){
	if(prepageNo!='null'&&prepageNo!=null){
		dwpanduan = true;
		dwid = preid;
		pageNumber = prepageNo;
		getZsHaocaifpyeByPage(decodeURI(decodeURI(preMingcheng)));
		$("#hcpc-mingcheng").val(preMingcheng);
	}else{
		pageNumber = 1;
		dwpanduan = false;
		getZsHaocaifpyeByPage('');
	}
}

//定位参数
var dwid='';
var dingwei='';
//数据读取
function getZsHaocaifpyeByPage(mingcheng){
	var totalNumber=0;
	$.ajax({
		//请求方式为get
        type:"POST",
        //获取json文件路径
        url:"./kucunpc/getZsHaocaifpyeCount",
        //传送数据
        data:{mingcheng:mingcheng},
        async:false,
        //请求成功完成后要执行的方法
        success: function(data){
	    	totalNumber = data;
	    	if(totalNumber==0){
				$("#a-table-list").css("display","none");
				$("#hcku-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$("#a-table-list").css("display","block");
				$("#hcku-img").html("");
			}
    	}
    });
    	$('#kucunhc').html('');
    	var container = $('#pagination-fenypchc');
		container.pagination({
			dataSource:'./kucunpc/getZsHaocaifpyeByPage?mingcheng='+encodeURI(mingcheng),
			locator: ' ',
			pageSize: 12,
			pageNumber:pageNumber,
			totalNumber: totalNumber,
			showNavigator: true,
	   	    formatNavigator: '共 <%= totalNumber %> 条',
			callback: function(data, pagination){
				var content = '';
				$(data).each(function(index,value){
					var gongyingshang = this.gongyingshang || '';	
		        	var index=((pagination.pageNumber-1)*pagination.pageSize)+index+1;
					content += '<tr id="hcpchang'+this.id+'">'+
							   '<td width="5%">'+index+'</td>'+
							   '<td width="15%">'+this.pici+'</td>'+
							   '<td class="left"  width="13%">'+this.mingcheng+'</td>'+
							   '<td width="11%">'+this.baozhuanggg+'</td> '+
							   '<td class="left" width="12%">'+gongyingshang+'</td> '+
							   '<td width="10%">'+this.jinhuojia.toFixed(8)+'</td>'+
							   '<td width="10%">'+this.xiaoshoujia.toFixed(8)+'</td>'+
							   '<td width="10%">'+this.rukusl+this.rukudw+'</td> '+
							   '<td width="10%" class="haocai-picicz"><span style="color:#00b472;" onclick="toHaocaipcxq('+this.id+','+pagination.pageNumber+',\''+mingcheng+'\')">编辑</span></td></tr>';
				});
			  $('#kucunhcpc').html(content);
			  if(dwpanduan){
				  $('#kucunhcpc').find('tr[id="hcpchang'+dwid+'"]').addClass('list-tr');
			  } else {
				  $('#kucunhcpc').find('tr[id="hcpchang'+dwid+'"]').removeClass('list-tr');
			  }
			}
		});
	if(totalNumber <= 12) {
		$('#pagination-fenypchc').css('display','none');
	}else{
		$('#pagination-fenypchc').css('display','block');
	}
}

//查询按钮
$("#hcpc-search").click(function(){
	pageNumber = 1;
	dwpanduan = false;
    getZsHaocaifpyeByPage($("#hcpc-mingcheng").val().trim());
});

// 查询重置
$("#hcpc-reset").click(function(){
	$("#hcpc-mingcheng").val('');
	pageNumber = 1;
	dwpanduan = false;
    getZsHaocaifpyeByPage('');
});
//进入耗材详情页面
function toHaocaipcxq(id,prepageNo,dwming){
	var dwpageNo = prepageNo;
	dwmingcheng = encodeURI(encodeURI(dwming));
	$("#cedan").load(path + "/views/kucun/kucun-pici/bianjihc-kc.jsp?ID="+id+"&dwmingcheng="+dwmingcheng+"&dwpageNo="+dwpageNo);
}
